package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CMiddleCheckDao;
import com.hongxun.modules.csg.entity.CMiddleCheckEntity;
import com.hongxun.modules.csg.service.CMiddleCheckService;



@Service("cMiddleCheckService")
public class CMiddleCheckServiceImpl implements CMiddleCheckService {
	@Autowired
	private CMiddleCheckDao cMiddleCheckDao;
	
	@Override
	public CMiddleCheckEntity queryObject(String guid){
		return cMiddleCheckDao.queryObject(guid);
	}
	
	@Override
	public List<CMiddleCheckEntity> queryList(Map<String, Object> map){
		return cMiddleCheckDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cMiddleCheckDao.queryTotal(map);
	}
	
	@Override
	public void save(CMiddleCheckEntity cMiddleCheck){
		if(cMiddleCheck.getGuid()==null||cMiddleCheck.getGuid().equals("")) {
			cMiddleCheck.setGuid(UUID.randomUUID().toString());
		}

		cMiddleCheckDao.save(cMiddleCheck);
	}
	
	@Override
	public void update(CMiddleCheckEntity cMiddleCheck){
		cMiddleCheckDao.update(cMiddleCheck);
	}
	
	@Override
	public void delete(String guid){
		cMiddleCheckDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cMiddleCheckDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CMiddleCheckEntity> entities) {
		for (CMiddleCheckEntity d : entities) {
			if (d.getMCDatastate().equals("删除")) {
				cMiddleCheckDao.delete(d.getGuid());
			} else {
				CMiddleCheckEntity cMiddleCheckEntity = cMiddleCheckDao.queryObject(d.getGuid());
				if (cMiddleCheckEntity == null) {
					cMiddleCheckDao.save(d);
				} else {
					cMiddleCheckDao.update(d);
				}
			}
		}
	}
	
}
